<?php


namespace App\Http\Repositories\Admin\Base;


use App\Http\Repositories\BaseRepository;
use App\Models\Base\TagsModel;

class TagsRepository extends BaseRepository
{
    public $tags;
    public function __construct(TagsModel $tags)
    {
        $this->tags = $tags;
    }

    /**
     * 添加
     * @param $data
     * @return mixed
     */
    public function addTags($data)
    {
        $insert['type'] = $data['type'];
        $insert['name'] = $data['name'];
        $insert = $this->tags->setUserInfo($insert);

        return $this->tags->create($insert);
    }

    /**
     * 获取详情
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\ApiException
     */
    public function getTagsInfo($data)
    {
        return $this->tags->getInfo($data);
    }

    /**
     * 获取列表
     * @param $data
     * @return mixed
     */
    public function getTagsList($data)
    {
        is_real_exists(@$data['type']) && $where['type'] = $data['type'];
        is_real_exists(@$data['name']) && $where['name'] = ['like', $data['name'].'%'];

        if ($data['operate_type'] == 1)
            return $this->tags->getListByPage($where ?? []);
        return $this->tags->getList($where ?? []);
    }

    /**
     * 删除
     * @param $data
     * @return array|string[]
     */
    public function delTags($data)
    {
        return $this->tags->deleteItem($data);
    }

    /**
     * 编辑
     * @param $data
     * @return array
     * @throws \App\Exceptions\ApiException
     */
    public function editTags($data)
    {
        $where['id'] = $data['id'];

        return $this->tags->editItem($where, $data);
    }
}
